using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace QuanLyHocPhi.Model.Mapping
{
    public class SinhVienMap : EntityTypeConfiguration<SinhVien>
    {
        public SinhVienMap()
        {
            // Primary Key
            this.HasKey(t => t.MaSinhVien);

            // Properties
            this.Property(t => t.MaSinhVien)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.HoDem)
                .HasMaxLength(50);

            this.Property(t => t.Ten)
                .HasMaxLength(50);
            this.Property(t => t.Dien)
               .HasMaxLength(100);
            this.Property(t => t.DoiTuong)
                .HasMaxLength(100);
            this.Property(t => t.NgaySinh)
                .HasMaxLength(50);

            this.Property(t => t.GhiChu)
                .HasMaxLength(250);

            this.Property(t => t.MaLopGoc)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("SinhVien");
            this.Property(t => t.MaSinhVien).HasColumnName("MaSinhVien");
            this.Property(t => t.HoDem).HasColumnName("HoDem");
            this.Property(t => t.Ten).HasColumnName("Ten");
            this.Property(t => t.Dien).HasColumnName("Dien");
            this.Property(t => t.DoiTuong).HasColumnName("DoiTuong");
            this.Property(t => t.Giam).HasColumnName("Giam");
            this.Property(t => t.GioiTinh).HasColumnName("GioiTinh");
            this.Property(t => t.NgaySinh).HasColumnName("NgaySinh");
            this.Property(t => t.GhiChu).HasColumnName("GhiChu");
            this.Property(t => t.MaLopGoc).HasColumnName("MaLopGoc");

            // Relationships
            this.HasOptional(t => t.LopGoc)
                .WithMany(t => t.SinhVienList)
                .HasForeignKey(d => d.MaLopGoc);

        }
    }
}
